import { _decorator, Component, Node, BoxColliderComponent, CCFloat } from 'cc';
import { GameApp } from '../GameApp';
import { enemyBase } from './enemyBase';
const { ccclass, property } = _decorator;

@ccclass('playerSkillCollider')
export class playerSkillCollider extends Component {
    private _colliderCom: BoxColliderComponent = null
    // @property({ displayName: "伤害类型" })
    // protected skillType: number = 1

    @property({ displayName: "持续伤害" })
    public isDot: boolean = false
    @property({ type: CCFloat, displayName: "技能伤害倍数" })
    public AP: number = 3;//伤害倍数

    private hitNum: number = 0

 



    start() {

    }
    onEnable() {
        if (this.isDot) {
            this._colliderCom.on('onTriggerStay', this._onTriggerEnterCb, this);

        } else {
            this._colliderCom.on('onTriggerEnter', this._onTriggerEnterCb, this);
        }

    }

    onDisable() {
        if (this.isDot) {
            this._colliderCom.off('onTriggerStay', this._onTriggerEnterCb, this);

        } else {
            this._colliderCom.off('onTriggerEnter', this._onTriggerEnterCb, this);
        }
    }
    onLoad() {
        this._colliderCom = this.node.getComponent(BoxColliderComponent) as BoxColliderComponent;
      
        //先计算伤害
        if (this.isDot) {


            this.hitNum = this.AP * GameApp.Instance.playerData.gongji / 60

        } else {
            this.hitNum = this.AP * GameApp.Instance.playerData.gongji

        }

    }
    private _onTriggerEnterCb(event) {




        let otherCollider = event.otherCollider;
        let enemy: enemyBase = otherCollider.node.getComponent(enemyBase)
        if (enemy && (!enemy.isDie)) {
   

           
            
            enemy.hit(this.hitNum, GameApp.Instance.player, this.isDot)

        }








    }
    update(deltaTime: number) {

    }
}


